<template>
	<view class="app">
		<u-row justify="center">
			<u--image   height="350rpx" width="350rpx" :src="src" mode="widthFix"></u--image>
		</u-row>
 
				<u-cell  :border='false' title=" "></u-cell>
				<u-cell  :border='false' title=" "></u-cell>
		 
		<u-row class="u-m-t-50">
			<u-col span="8" offset="2">
				 <u--input
					type="number"
				    placeholder="请输入手机号"
				    border="surround"
				    v-model="mobile" 
					shape="circle"
				  ></u--input>
			</u-col>
		</u-row>
		<u-cell  :border='false' title=" "></u-cell>
		 <u-row class=" ">
			<u-col span="8" offset="2">
				 <u--input
					placeholder="请输入密码"
					border="surround"
					v-model="password"
				   :password = 'true'
					shape="circle"
				  ></u--input>
			</u-col>
		 </u-row>
		 <u-cell  :border='false' title=" "></u-cell>
		<u-row>
			<u-col span="8" offset="2"   >
				<u-button v-if="!login" type="primary" shape="circle"  text=" 登录 " @click=" tosubmitlogin "></u-button>
				<u-button v-else type="primary" shape="circle"  text=" 注册 " @click=" tologin"></u-button>
			</u-col>
		</u-row>
		<u-cell  :border='false' title=" "></u-cell>
		 <u-row   >
		 	<u-col span="3" offset="3"   textAlign='center'>
				<text v-if="!login" style="color:#00aaff;" @click="login =!login">注册账号</text>
				<text v-else style="color:#00aaff;" @click="login =!login">已有账号</text>
		 		 
		 	</u-col>
			<u-col>
				<text span="3" style="color:#00aaff;" @click="reset">忘记密码</text>
			</u-col>
		 </u-row>
		
		<!-- <u-popup border-radius="10" v-model="show"
		@close="close" @open="open" :mode="mode" 
		length="50%" :mask="mask"
		:closeable="closeable"
		:close-icon-pos="closeIconPos"
	>
		
	</u-popup> -->
	</view>
</template>

<script>
	var that
	var UserInfo = require('../../../service/UserInfo.js'),mUserInfo
	import {
		checkStr
	} from '@/common/js/util'
	import WXBizDataCrypt from '../../../tools/WXBizDataCrypt.js'
	// import loginMpWx from './mixin/login-mp-wx.js'
	// import loginAppWx from './mixin/login-app-wx.js'
	// import loginApple from './mixin/login-apple.js'
	export default {
		// mixins: [loginMpWx, loginAppWx, loginApple],
		data() {
			return {
				src:'/static/logo.png',
				login:false,
				size: 34,
				wrap: false,
				width: 'auto',
				max: 3,
				activeColor: '#7468BE',
				checked: false,
				mobile: '',
				password: '',
				isAccount: false,
				show: false,
				mode: 'bottom',
				mask: true, // 是否显示遮罩
				closeable: true,
				closeIconPos: 'top-right',
				autoStatus: true,
				sessionKey: '', 
				openId: '',
				session_key: '',
				phoneNumber: '',
				isLoginPage : true
			};
		},
		onLoad() {
			 
			that = this
			that.show = true
			mUserInfo = new UserInfo(this.mNetTool)
		 
		},
		mounted() {
		 let info = uni.getStorageSync('userpassword')
			 that.password = info.password
			 that.mobile = info.mobile
		},
		
		methods: {
			reset(){
				uni.navigateTo({
					url:'reset/reset'
				})
			},
			tologin(){
				uni.showLoading({
				title:'请稍等'
				})
				 
				mUserInfo.list({
					mobile:that.mobile,
				},res => {
					uni.hideLoading()
					if(res.records >= 1){
						uni.$u.toast('该账户已存在') 
						return
					}else{
						let account = {
							mobile:that.mobile,
							password:that.password
						}
						console.log('login')
						this.mNetTool.getAjaxUrlValueBackground('capi/loomoSMS/getCode',{
								mobile:that.mobile,
								signature:'商品过期管家'
						},res => {
							console.log(res)
							if(res.success){
							uni.hideLoading()
								uni.navigateTo({
									url:'code?mobile='+account.mobile+'&pass='+account.password
								})
							}
						})
					}
				})
			
				
			},
			checkboxChange(e) {
				that.checked = e.value
				console.log(that.checked, e)
				console.log(e.value)
			},
			loginSuccessCallBack(data) {
				this.$util.msg('登陆成功');
				this.$store.commit('setToken', data);
				uni.switchTab({
					url: '../home/home'
				})
				console.log('logsucess')
			},
			// tosubmitlogin(){
			// 	console.log(123)
			// 	uni.$u.throttle(this.submitlogin, 2000)
			// },
			tosubmitlogin( ) {
				let that = this
				uni.showLoading({
						title:'正在登录中'
				})
			 
				if(!uni.$u.test.mobile(that.mobile)){
					uni.$u.toast('请输入正确的手机号')
					uni.hideLoading()
					return
				}
				if(uni.$u.test.isEmpty(that.password)){
					uni.$u.toast('请输入密码')
					uni.hideLoading()
					return
				}
				if(!that.password){
					that.password = 123456
				}
				 mUserInfo.list({
					 mobile:that.mobile,
					 password:that.password
				 },res => {
					 console.log(res)
					 if(res.records === 1){
						 uni.setStorageSync('userInfo',res.rows[0])
						 uni.setStorageSync('isLogin',true)
						 uni.$u.toast('登录成功')
						 uni.switchTab({
						 	url:'../home/home'
						 })
						uni.hideLoading()
					 }else {
						uni.hideLoading()
						 uni.$u.toast('账户或密码错误，请检查')
					 }
				 })
				 return
				uni.setStorageSync('userpassword',info)
				 mUserInfo.login(info, res => {
				 console.log('111111111111',res)
				 if (res.login) {
				 
				 	uni.hideToast()
					uni.$u.toast('登录成功')
				 	uni.switchTab({
				 		url: '../home/home'
				 	})
				 	uni.setStorageSync('userInfo', res.rows[0])
				 	console.log(res.rows[0])
				 	// uni.setStorageSync('token',token)
				 	uni.setStorageSync('isLogin', true)
				 	} else {
				 		uni.setStorageSync('isLogin', false)
				 	}
				 
				 })
				if (that.isAccount) {
					that.loginByPhon()
					return

				}
			},



		},
		

	}
</script>

<style lang="scss" scoped>
 
  
 
</style>
